package fun.tan90.wx.pay.statemachine;


import fun.tan90.wx.pay.entity.Order;
import lombok.RequiredArgsConstructor;
import org.springframework.statemachine.StateMachine;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class OrderStateMachineManager {

    final StateMachine<OrderStatus, OrderEvent> stateMachine;

    // 处理订单支付事件
    public void processPayment(Order order) {
        // 发送 PAY 事件触发状态转换
        stateMachine.sendEvent(OrderEvent.PAY);
    }

    // 处理订单发货事件
    public void processShipping(Order order) {
        // 发送 SHIP 事件触发状态转换
        stateMachine.sendEvent(OrderEvent.SHIP);
    }

    // 处理订单完成事件
    public void processCompletion(Order order) {
        // 发送 COMPLETE 事件触发状态转换
        stateMachine.sendEvent(OrderEvent.COMPLETE);
    }

}
